﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWeb.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="js/CTSZ.Source.js" type="text/javascript"></script>
    <script src="js/EntLibValidation.js" type="text/javascript"></script>
    <style>
        body{line-height:30px;font-size:85%;}
        .tip{position:absolute;z-index:1000;border:1px solid #a6202b;background:#FFF0CF;padding:2px 2px;color:#a6202b;max-weight:250px;height:18px;line-height:18px;}
        .tip .warnning{background:url(../Imgs/bg.png) no-repeat -20px 0;width:20px;height:20px;float:left;}    
        .shadow{-moz-box-shadow:2px 2px 5px #333333;-webkit-box-shadow:2px 2px 5px #333333;box-shadow:2px 2px 5px #333333;filter:progid:DXImageTransform.Microsoft.Shadow(color='#666666', Direction=135, Strength=3);}
        .radius{-moz-border-radius: 5px;-khtml-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;}        
    </style>
</head>
<body>
    <form id="form1" runat="server" onsubmit="return validate(this)">
    <div>
    
        <div class="item">
            Name <asp:TextBox ID="txtName" runat="server" />
        </div>

        <div class="item">
            Birthday <asp:TextBox runat="server" ID="txtBirthday" />
        </div>

        <div class="item">
            Sex <asp:RadioButtonList runat="server" ID="rblSex" RepeatLayout="Flow" RepeatDirection="Horizontal">
                <asp:ListItem Text="Male" Value="Male" />
                <asp:ListItem Text="Famale" Value="Famale" />
                <asp:ListItem Text="Shemale" Value="Shemale" />
            </asp:RadioButtonList>
        </div>

        <div class="item">
            Email <asp:TextBox runat="server" ID="txtEmail" />
        </div>

        <div class="item">
            Reinput Email <asp:TextBox runat="server" ID="txtReEmail" />
        </div>

        <div>
            <table>
                <thead>
                    <tr>
                        <th>Project</th>
                        <th>Score</th>
                    </tr>
                </thead>
                <tr>
                    <td><asp:TextBox ID="txtProject1" runat="server" /></td>
                    <td><asp:TextBox ID="txtScore1" runat="server" /></td>
                </tr>

                <tr>
                    <td><asp:TextBox ID="txtProject2" runat="server" /></td>
                    <td><asp:TextBox ID="txtScore2" runat="server" /></td>
                </tr>
            </table>
        </div>

        <asp:Button ID="btnSubmit" runat="server" Text="OK" />
    </div>
    </form>

   <script>
        var rule = <%= this.Rules %>

//        rule.push({ name:'txtReEmail' , required:true , type:'Repeat' , to:'txtEmail', operator:'==' , msg:'' , tag:'' });
//        rule.push({ name:"rblSex", type:"Group", required:true , min:1, noSelected:'Shemale' , msg:"请选择性别,不能为人妖" });

        //同一控件可以应用多个规则,注意:如果前面的规则失败,而后面的规则失败的处理.
        var customValidHelper = {};
        (function(o){

	        o.pass = function(obj,rule){

                if(obj.length != undefined && obj.length > 0)
                    obj = obj[obj.length - 1];

                if(FormValidateForEntLib.allPass(obj)){
		            try{
			            document.body.removeChild(obj.errorTip);
			            obj.errorTip = null
		            }catch(e){}
                }
	        }

	        o.unPass = function(obj,rule){

                if(obj.length != undefined && obj.length > 0)
                    obj = obj[obj.length - 1];

		        if(!obj.errorTip){
			        var tmp = document.createElement("DIV");
			        tmp.className = "tip shadow radius";
			        document.body.appendChild(tmp);
			        obj.errorTip = tmp;
			        obj.errorTip.innerHTML = "<span class='warnning'></span>" + FormValidateForEntLib.getMessage( rule );
		        }else{
			        obj.errorTip.innerHTML = "<span class='warnning'></span>" + FormValidateForEntLib.getMessage( rule );
		        }

                var tipFollow;
                if(rule.tag && CTSZ.$(rule.tag)){
                    tipFollow = CTSZ.$(rule.tag);
                }else{
                    tipFollow = obj;
                }

                var pos = CTSZ.getAbsPos(tipFollow);
                CTSZ.css(obj.errorTip, {left:pos.x + tipFollow.offsetWidth , top:pos.y - 8});

	        }

        })(customValidHelper);

        var va = FormValidateForEntLib.getInstance();
        var validate = function (form) {
            var f = va.validate(form, rule, 3, customValidHelper.pass, customValidHelper.unPass);
            return f !== false;
        }        
    </script>
</body>
</html>
